<template>
  <div class="winform-container">
    <div class="winform-header">
      <h2>登录</h2>
    </div>
    <div class="winform-content">
      <form @submit.prevent="handleLogin">
        <div class="form-group">
          <label for="userName">用户名</label>
          <input
            type="text"
            id="userName"
            v-model="userName"
            placeholder="请输入用户名"
            required
          >
        </div>
        <div class="form-group">
          <label for="pwd">密码</label>
          <input
            type="password"
            id="pwd"
            v-model="pwd"
            placeholder="请输入密码"
            required
          >
        </div>
        <div v-if="errorMessage" class="error-message">{{ errorMessage }}</div>
        <div class="form-actions">
          <button type="submit" class="btn-login">登录</button>
        </div>
      </form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

defineOptions({
  name: 'WinFrom',
});

const userName = ref('');
const pwd = ref('');
const errorMessage = ref('');

const handleLogin = () => {
  if (userName.value === 'admin' && pwd.value === '123') {
    errorMessage.value = '';
    alert('登录成功！');
    // 这里可以添加登录成功后的逻辑，比如跳转到主页
  } else {
    errorMessage.value = '用户名或密码错误，请重试。';
  }
};
</script>

<style scoped>
.winform-container {
  width: 400px;
  margin: 100px auto;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  background-color: #f8f8f8;
  font-family: Arial, sans-serif;
}

.winform-header {
  background-color: #0078d7;
  color: white;
  padding: 15px;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}

.winform-header h2 {
  margin: 0;
  font-size: 18px;
}

.winform-content {
  padding: 20px;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}

.form-group input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 3px;
  box-sizing: border-box;
}

.error-message {
  color: red;
  margin-bottom: 15px;
}

.form-actions {
  text-align: center;
}

.btn-login {
  background-color: #0078d7;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 16px;
}

.btn-login:hover {
  background-color: #005a9e;
}
</style>